class RoomsController < ApplicationController
  
    before_filter :ensure_login
  
    def index
        @rooms = Room.find(:all, :conditions => "id > 0")
         
        respond_to do |format|
            format.html # index.html.erb
            format.xml  { render :xml => @rooms }
        end
    end
  
    # GET /rooms/1
    # GET /rooms/1.xml
    def show
        @room = Room.find(params[:id])
        @machines = @room.machines
    
        respond_to do |format|
            format.html # show.html.erb
            format.xml  { render :xml => @room }
        end
    end
  
    # GET /rooms/new
    # GET /rooms/new.xml
    def new
        @room = Room.new
    
        respond_to do |format|
            format.html # new.html.erb
            format.xml  { render :xml => @room }
        end
    end
  
    # GET /rooms/1/edit
    def edit
        @room = Room.find(params[:id])
    end
  
    # POST /rooms
    # POST /rooms.xml
    def create
        @room = Room.new(params[:room])
    
        respond_to do |format|
            if @room.save
                flash[:notice] = 'room was successfully created.'
                format.html { redirect_to(@room) }
                format.xml  { render :xml => @room, :status => :created, :location => @room }
            else
                format.html { render :action => "new" }
                format.xml  { render :xml => @room.errors, :status => :unprocessable_entity }
            end
        end
    end
  
    # PUT /rooms/1
    # PUT /rooms/1.xml
    def update
        @room = Room.find(params[:id])
    
        respond_to do |format|
            if @room.update_attributes(params[:room])
                flash[:notice] = 'room was successfully updated.'
                format.html { redirect_to(@room) }
                format.xml  { head :ok }
            else
                format.html { render :action => "edit" }
                format.xml  { render :xml => @room.errors, :status => :unprocessable_entity }
            end
        end
    end
  
    # DELETE /rooms/1
    # DELETE /rooms/1.xml
    def destroy
        @room = Room.find(params[:id])
        @room.destroy
    
        respond_to do |format|
            format.html { redirect_to(rooms_url) }
            format.xml  { head :ok }
        end
    end

end
